Can someone please point me in the right direction with a code snippet to parse a file. |
Re: DXL to parse a file Are you able to post the format of this log file? If not then I will create a custom log file and show you how I parse that out. |
Re: DXL to parse a file pete.kowalski - Mon Jul 06 22:24:59 EDT 2009
Here is a quick example I just thought of.
Stream inFile = read "D:\\log.txt"
string fooString
Regexp myReg = regexp "[0-9]+"
while (true)
{
inFile >> fooString
if (end inFile)
{
infoBox "nothing else to read in file"
break
}
if (matches(":",fooString))
{
if (myReg fooString)
{
print fooString[match 0] "\n"
}
}
}
close(inFile)
Attachments attachment_14270918_log.txt |
Re: DXL to parse a file pete.kowalski - Mon Jul 06 22:34:52 EDT 2009
Here is a quick example I just thought of.
Stream inFile = read "D:\\log.txt"
string fooString
Regexp myReg = regexp "[0-9]+"
while (true)
{
inFile >> fooString
if (end inFile)
{
infoBox "nothing else to read in file"
break
}
if (matches(":",fooString))
{
if (myReg fooString)
{
print fooString[match 0] "\n"
}
}
}
close(inFile)
Thanks Pete! With a few tweaks I was able to get your code to work. It was the stream manipulation bit I wasn't sure of. ******************************************************************************* History check on /My Project/My Module, begun 6/26/2009 07:23:20 - Not checking baselined history. - Checking attribute values in Deleted objects. ******* Attribute value mismatch: Proposed Change ******* History entry details in current version: modifyObject Object: 17818 Session: 4254 User: mcnairk Date: 3/12/2009 10:19:30 Summary of results: 1 Attribute values not matching values in history. History check completed at 6/26/2009 07:23:33 |
Re: DXL to parse a file
sen "mismatch" $log The above 2-liner will print the number of occurrences of string "mismatch". The script is in biterscripting ( Link: http://www.biterscripting.com ) . Sen |
Re: DXL to parse a file
That pervious post did not look alright. Here is the one that should look better. # Script mismatch.txt var str log ; cat "C:\somefile.log" > $log sen "^mismatch^" $log
|
Re: DXL to parse a file mcnairk - Tue Jul 07 10:43:47 EDT 2009
Thanks Pete! With a few tweaks I was able to get your code to work. It was the stream manipulation bit I wasn't sure of. ******************************************************************************* History check on /My Project/My Module, begun 6/26/2009 07:23:20 - Not checking baselined history. - Checking attribute values in Deleted objects. ******* Attribute value mismatch: Proposed Change ******* History entry details in current version: modifyObject Object: 17818 Session: 4254 User: mcnairk Date: 3/12/2009 10:19:30 Summary of results: 1 Attribute values not matching values in history. History check completed at 6/26/2009 07:23:33 Good to hear. With the sample log file what do you want parsed out? Just curious because the code I came up with was on the fly and naturally not optimized. |
Re: DXL to parse a file pete.kowalski - Sat Jul 11 18:48:12 EDT 2009
Here's my code:
Stream inFile = read Filename
string fooString
while (true)
{
inFile >> fooString
if (end inFile)
{break}
if (matches("mismatch",fooString))
{count++}
}
close(inFile)
if (count == 0)
{infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
{
if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
}
}
|
Re: DXL to parse a file mcnairk - Mon Jul 13 08:18:14 EDT 2009
Here's my code:
Stream inFile = read Filename
string fooString
while (true)
{
inFile >> fooString
if (end inFile)
{break}
if (matches("mismatch",fooString))
{count++}
}
close(inFile)
if (count == 0)
{infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
{
if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
}
}
I discovered a logic error that a match detected in the last line in the file is not detected. The test for the end of the file needs to be moved after the match statement:
Stream inFile = read Filename
string fooString
while (true)
{
inFile >> fooString
if (matches("mismatch",fooString))
{count++}
if (end inFile)
{break}
}
close(inFile)
if (count == 0)
{infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
{
if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
}
}
|
Re: DXL to parse a file mcnairk - Mon Jul 13 14:52:26 EDT 2009
I discovered a logic error that a match detected in the last line in the file is not detected. The test for the end of the file needs to be moved after the match statement:
Stream inFile = read Filename
string fooString
while (true)
{
inFile >> fooString
if (matches("mismatch",fooString))
{count++}
if (end inFile)
{break}
}
close(inFile)
if (count == 0)
{infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
{
if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
}
}
Attached is the txt file which i want to parse it. in the txt file I have the tags "#IssueStart#" and #IssueEnd#, within that i have some values ie. if issuekey= somevalue then i have to create a new object at the last of the module. I have to update the attributes to the newly created object with the values present in txt file like in the txt file i have a Objectheading = #start#"xyz"#End#,i have to get the value between the two tags #start# and #end#. similarly for other attributes. I have to create an object for every "#IssueStart#" and #IssueEnd# in the txt file Kindly help me.. Kindly let me know if any further details are required. Thank you! Regards, Shruthi Attachments attachment_14689018_New_Text_Document.txt |